<!DOCTYPE html>
<html>
<head> 
<meta charset="UTF-8">
	<title>baby&mama</title> 

	
	<link rel="stylesheet" type="text/css" href="jquery.mobile-1.1.0.min.css" />

<link rel="stylesheet" type="text/css" href="jquery.mobile.datebox.min.css" /> 
<script type="text/javascript" src="jquery-1.6.4.min.js"></script> 
<script type="text/javascript" src="jquery.mobile-1.0.1.min.js"></script>

<!-- Optional Mousewheel support: http://brandonaaron.net/code/mousewheel/docs 
<script type="text/javascript" src="PATH/TO/YOUR/COPY/OF/jquery.mousewheel.min.js"></script>-->
<script type="text/javascript" src="jquery.mobile.datebox.min.js"></script>
<script type="text/javascript" src="jquery.mobile.datebox.i8n.en.js"></script>
 <script type="text/javascript" charset="utf-8" src="cordova-1.7.0rc1.js"></script>

</head> 
<body>
<div data-role="page">

	<div data-role="header" data-theme="b">
	<a href="pregnancyCare.html" data-role="button" data-theme="b" rel="external" data-inline="true">Back</a>
		<h1>baby&mama</h1>
	</div><!-- /header -->
	
            <div data-role="content">
                <form url="" action="POST">
                    <div data-role="fieldcontain">
                        <fieldset data-role="controlgroup">
                            <label for="textinput2">
                                Tên
                            </label>
                            <input id="textinput2"  name="name" placeholder="" value="" type="text" />
                        </fieldset>
                    </div>
                    <div data-role="fieldcontain">
                        <fieldset data-role="controlgroup">
                            <label for="textinput3">
                                Tuổi
                            </label>
                            <input id="textinput3" placeholder="" value="" type="text" />
                        </fieldset>
                    </div>
                    <div data-role="fieldcontain">
                        <fieldset data-role="controlgroup">
                            <label for="textinput4">
                                Cân nặng
                            </label>
                            <input id="textinput4" placeholder="" value="" type="text" />
                        </fieldset>
                    </div>
                    <div data-role="fieldcontain">
                        <fieldset data-role="controlgroup">
						<label for="mydate">Ngày kinh cuối</label> <input name="mydate"
							id="mydate" type="date" data-role="datebox"
							data-options='{"mode": "calbox"}'>
					</fieldset>
                    </div>
                    <input value="Lưu" type="button" onclick="saveData(this.form);" />
                </form>
            </div>
            <div id="resultDiv" style="display: none;">
            </div>
            <div data-role="footer" data-theme="b"><center> baby&mama</center></div>
<!-- /footer --></div>
	</div>
	
        <script>
            //App custom javascript
        </script>
    </body>
    <script type="text/javascript">
    function onLoad() {
        document.addEventListener("deviceready", onDeviceReady, false);
    }
    // Cordova is ready
    //
    function onDeviceReady() {
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess, fail);
    }

    function onSuccess(fileSystem) {
        //fileSystem.root.getFile("readme.txt", null, gotFileEntry, fail);
        console.log(fileSystem.name);
    }
    
		function saveData(form){
			 var mydate = form.mydate.value;
			 mydate = new Date(mydate);
			    var deliverDate = new Date(); 
			    deliverDate = new Date(mydate.getTime() + 280*24*60*60*1000);
			    //deliverDate.format("dd/m/yy");
			    var msg = " Bạn dự sinh vào " + deliverDate.getDate() + "/" + (deliverDate.getMonth()+1); ;
			    // deliverDate.getYear();
			 $('#resultDiv').html(msg); 
			 $('#resultDiv').show();

			 deliverDate = new Date(mydate.getTime() + 7*24*60*60*1000);
			 var month = deliverDate.getMonth();
			 var monthDel = 0;
			 if(month > 3){
				 monthDel = month - 3;
			 }else{
				 var monthDel = month + 9;
		     } 

			 msg  += ". Theo luật Nagale bạn sẽ dự sinh vào " + deliverDate.getDate() + "/" + (monthDel+1) + " (ngày/tháng)";
			 $('#resultDiv').html(msg); 

			 console.log("Read as data URL");
			// fileSystem.root.getFile("readme.txt", {create: true}, gotFileEntry, fail);
			 //gotFile()
			 console.log("scc");
			 
			 /*
			 
			 
Luật Nagele (+7/-3)

			 base on 28-day frequency
			 */
		}
		function gotFileEntry(fileEntry) {
	        fileEntry.file(gotFile, fail);
	    }

		function gotFile(file){
	        readDataUrl(file);
	        readAsText(file);
	    }

	    function readDataUrl(file) {
	        var reader = new FileReader();
	        reader.onloadend = function(evt) {
	            console.log("Read as data URL");
	            console.log(evt.target.result);
	        };
	        reader.readAsDataURL(file);
	    }

		
    </script>
</html>